package com.huasheng.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.huasheng.dao.EmployeeDao;
import com.huasheng.dao.StoryDao;
import com.huasheng.entity.EmployeeEntity;
import com.huasheng.entity.StoryEntity;
import com.huasheng.service.EmployeeService;
import com.huasheng.service.StoryService;
import com.huasheng.util.DateUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * 员工管理
 *
 * @author Joey
 * @Email wangguoqing_it@163.com
 */
@Service
public class EmployeeServiceImpl extends ServiceImpl<EmployeeDao, EmployeeEntity> implements EmployeeService {


    @Resource
    private EmployeeDao dao;


    @Override
    @Transactional
    public void save(EmployeeEntity user) throws Exception {
        user.setCreateTime(DateUtils.getCurrentUnixTime());
        // sha256加密
        baseMapper.insert(user);
    }

    @Override
    @Transactional
    public void deleteBatch(Long[] userId) {
        baseMapper.deleteBatch(userId);
    }


    @Override
    @Transactional
    public void update(EmployeeEntity entity) {
    }

    @Override
    public Page<EmployeeEntity> queryListByPage(Integer offset, Integer limit, String email, String userName,
                                               String sort, Boolean order) {
        Wrapper<EmployeeEntity> wrapper = new EntityWrapper<EmployeeEntity>();
        if (StringUtils.isNoneBlank(sort) && null != order) {
            wrapper.orderBy(sort, order);
        }
        if (StringUtils.isNoneBlank(userName)) {
            wrapper.like("username", userName);
        }
        if (StringUtils.isNoneBlank(email)) {
            wrapper.like("email", email);
        }
        Page<EmployeeEntity> page = new Page<>(offset, limit);
        return this.selectPage(page, wrapper);
    }

    @Override
    public int updateAvatar(EmployeeEntity entity) {
        int update = 1;
        return update;
    }

    @Override
    public int updateStatus(Long userId, int status) {
        return 1;
    }

}
